#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#define MAX_SIZE 100
typedef struct
{
	int data[MAX_SIZE];
	int top;
}Stack;
void initializeStack(Stack* stack)
{
	stack->top = -1;
}
int isEmpty(Stack* stack)
{
	return stack->top == -1;
}
int isFull(Stack* stack)
{
	return stack->top == MAX_SIZE;
}
void push(Stack* stack, int value)
{
	if (!isFull(stack))
	{
		stack->data[++stack->top] = value;
	}
}
int pop(Stack* stack)
{
	if (!isEmpty(stack))
	{
		return stack->data[stack->top--];
	}
	return -1;
}
int top(Stack* stack)
{
	if (!isEmpty(stack))
	{
		return stack->data[stack->top];
	}
	return  - 1;
}
void reverseStack(Stack* stack)
{
	if (!isEmpty(stack))
	{
		int temp = pop(stack);
		reverseStack(stack);
		push(stack, temp);
	}
}
int main()
{
	Stack stack;
	initializeStack(&stack);
	int data;
	while (scanf("%d", &data) && data != 0)
	{
		push(&stack,data);
	}
	reverseStack(&stack);
	while (!isEmpty(&stack))
	{
		printf("%d", pop(&stack));
		if (!isEmpty(&stack))
		{
			printf(" ");
		}
	}
	return 0;
}